"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.恶灵Handler = void 0;
const Config_1 = require("../../Config");
const Big_1 = require("../core/Big");
const GameUtils_1 = __importDefault(require("../GameUtils"));
const BaseHandler_1 = require("./BaseHandler");
class 恶灵Handler extends BaseHandler_1.BaseHandler {
    attack(data, player) {
        this.handlerMgr.spendAction(player, Config_1.Config.COST_恶灵_ATTACK);
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        big_start.actionOnce();
        let big_end = endPoint.big;
        if (big_end != null) {
            if (big_end.evolution == Big_1.BigEvolution.未转型) {
                if (big_end.arr_states.has(Big_1.BigState.FEAR)) {
                    if (!big_end.attacked(player)) {
                        big_start.die(player, endPoint.id);
                        return;
                    }
                }
                else {
                    big_end.deleteState(Big_1.BigState.HIDE);
                    big_end.addState(Big_1.BigState.FEAR);
                    big_start.die(player, endPoint.id);
                    return;
                }
            }
            else if (big_end.evolution == Big_1.BigEvolution.幽灵 || big_end.evolution == Big_1.BigEvolution.恶灵) {
                big_end.attacked(player);
            }
            else {
                big_start.die(player, endPoint.id);
                return;
            }
        }
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("恶灵_灵狩", { "start": data.start, "end": data.end }));
    }
    /**附身*/
    possess(data, player) {
        this.handlerMgr.spendAction(player, Config_1.Config.COST_恶灵_POSSESS);
        let startPoint = this.gameMgr.map_point.get(data.start);
        let endPoint = this.gameMgr.map_point.get(data.end);
        let big_start = startPoint.big;
        big_start.actionOnce();
        let big_end = endPoint.big;
        if (big_end != null) {
            if (big_end.evolution == Big_1.BigEvolution.未转型 && big_end.arr_states.has(Big_1.BigState.FEAR)) {
                this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("play_sound", { "sound": "恶灵_附身", "username": big_start.player.username }));
                big_end.possess(big_start);
                big_start.die(player, endPoint.id, false);
            }
            else {
                big_start.die(player, endPoint.id);
            }
            return;
        }
        startPoint.big = null;
        endPoint.big = big_start;
        big_start.point = endPoint;
        this.gameMgr.sendBroadcast(GameUtils_1.default.getObj("恶灵_附身", { "start": data.start, "end": data.end }));
    }
}
exports.恶灵Handler = 恶灵Handler;
